C++ ifstream eof()的使用 您所在的位置:网站首页 while eof怎么结束 C++ ifstream eof()的使用

C++ ifstream eof()的使用

2024-07-16 12:33| 来源: 网络整理| 查看: 265

C++ ifstream eof() 的使用 eof() 的使用方法1

ifstream.eof() 读到文件结束符时返回true。 大家可能有一个误区,认为读到文件结束符就是读到文件的最后一个字符。 其实不然,文件结束符是文件最后一个字符的下一个字符0xFF,eof() 读到文件结束符0xFF时返回true。

代码验证1

先来看看如下这段代码2:

#include #include #include using namespace std; int main() { char ch = 'x'; ifstream fin("test.txt" ); if (!fin) { cout fin.get(ch); cout cout fin.get(ch); if (fin.fail()) { cout cout //fin.get(ch); fin >> s; if (fin.fail()) { cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有